package top.fzqblog.firstapp;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ViewFlipper;

/**
 * Created by 抽离 on 2017/8/18 0018.
 */

public class ViewFlipperTest extends Activity {
    ViewFlipper viewFlipper;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.viewflippertest);
        viewFlipper = (ViewFlipper) findViewById(R.id.viewflipper);
    }

    private Float start ;

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Log.i("tag", "触发了触摸事件");
        switch (event.getAction()){
            case MotionEvent.ACTION_DOWN : {
                start = event.getX();
                break;
            }
            case MotionEvent.ACTION_MOVE : {
                break;
            }
            case MotionEvent.ACTION_UP : {
                if (event.getX() - start > 100) {
                    viewFlipper.showPrevious();
                }
                if (start - viewFlipper.getX() > 100) {
                    viewFlipper.showPrevious();
                }
                break;
            }
        }
        Log.i("tag", "start为" + start);
        return super.onTouchEvent(event);
    }
}
